# -*- coding: utf-8 -*-
"""
-------------------------------------------------
   File Name：     setting.py
   Description :   配置文件
   Author :        JHao
   date：          2019/2/15
-------------------------------------------------
   Change Activity:
                   2019/2/15:
-------------------------------------------------
"""

BANNER = r"""
****************************************************************
*** ______  ********************* ______ *********** _  ********
*** | ___ \_ ******************** | ___ \ ********* | | ********
*** | |_/ / \__ __   __  _ __   _ | |_/ /___ * ___  | | ********
*** |  __/|  _// _ \ \ \/ /| | | ||  __// _ \ / _ \ | | ********
*** | |   | | | (_) | >  < \ |_| || |  | (_) | (_) || |___  ****
*** \_|   |_|  \___/ /_/\_\ \__  |\_|   \___/ \___/ \_____/ ****
****                       __ / /                          *****
************************* /___ / *******************************
*************************       ********************************
****************************************************************
"""

VERSION = "2.4.0"

# ############### server config ###############


# ############### database config ###################
# db connection uri
# example:
#      Redis: redis://:password@ip:port/db
#      Ssdb:  ssdb://:password@ip:port
from enums.environment import Environment
# 获取当前环境
CURRENT_ENV = Environment.get_current_env()
# ############### 环境相关配置 ###############
ENV_CONFIG = {
    Environment.LOCAL: {
        "HOST": "0.0.0.0",
        "PORT": 5000,
        "DB_CONN": 'redis://@127.0.0.1:6379/1',
        "TABLE_NAME": 'use_proxy',
        "VERIFY_TIMEOUT": 10,
        "MAX_FAIL_COUNT": 0,
        "POOL_SIZE_MIN": 30,
        "PROXY_REGION": True,
        "HTTP_URL": "http://httpbin.org",
        "HTTPS_URL": "https://www.baidu.com",
    },
    Environment.TEST: {
        "HOST": "0.0.0.0",
        "PORT": 5000,
        "DB_CONN": 'redis://:JS^B9G61PP*ZI8Vf@172.16.49.120:20009/6',
        "TABLE_NAME": 'use_proxy_test',
        "VERIFY_TIMEOUT": 10,
        "MAX_FAIL_COUNT": 0,
        "POOL_SIZE_MIN": 30,
        "PROXY_REGION": True,
        "HTTP_URL": "http://httpbin.org",
        "HTTPS_URL": "https://www.baidu.com",
    },
    Environment.GRAY: {
        "HOST": "0.0.0.0",
        "PORT": 5000,
        "DB_CONN": 'redis://:JS^B9G61PP*ZI8Vf@172.16.49.120:20009/6',
        "TABLE_NAME": 'use_proxy_gray',
        "VERIFY_TIMEOUT": 10,
        "MAX_FAIL_COUNT": 0,
        "POOL_SIZE_MIN": 30,
        "PROXY_REGION": True,
        "HTTP_URL": "http://httpbin.org",
        "HTTPS_URL": "https://www.baidu.com",
    },
    Environment.PROD: {
        "HOST": "0.0.0.0",
        "PORT": 5000,
        "DB_CONN": 'redis://:JS^B9G61PP*ZI8Vf@172.16.49.120:20009/6',
        "TABLE_NAME": 'use_proxy_prod',
        "VERIFY_TIMEOUT": 10,
        "MAX_FAIL_COUNT": 0,
        "POOL_SIZE_MIN": 50,
        "PROXY_REGION": True,
        "HTTP_URL": "http://httpbin.org",
        "HTTPS_URL": "https://www.baidu.com",
    }
}


HEART_BEAT_INTERVAL = 10  # 心跳间隔时间(分钟)

# 根据当前环境加载配置
current_config = ENV_CONFIG[CURRENT_ENV]

# ############### server config ###############
HOST = current_config["HOST"]
PORT = current_config["PORT"]

# ############### database config #############
DB_CONN = current_config["DB_CONN"]
TABLE_NAME = current_config["TABLE_NAME"]

# ############### proxy validator #############
# 代理验证目标网站
HTTP_URL = current_config["HTTP_URL"]
HTTPS_URL = current_config["HTTPS_URL"]


# 代理验证时超时时间
VERIFY_TIMEOUT = current_config["VERIFY_TIMEOUT"]

# 近PROXY_CHECK_COUNT次校验中允许的最大失败次数,超过则剔除代理
MAX_FAIL_COUNT = current_config["MAX_FAIL_COUNT"]
# proxyCheck时代理数量少于POOL_SIZE_MIN触发抓取
POOL_SIZE_MIN = current_config["POOL_SIZE_MIN"]
# 是否启用代理地域属性
PROXY_REGION = current_config["PROXY_REGION"]


# ###### config the proxy fetch function ######
PROXY_FETCHER = [
    "pinzanProxy"
    # "freeProxy01",
    # "freeProxy02",
    # "freeProxy03",
    # "freeProxy04",
    # "freeProxy05",
    # "freeProxy06",
    # "freeProxy07",
    # "freeProxy08",
    # "freeProxy09",
    # "freeProxy10",
    # "freeProxy11"
]






# ############# scheduler config #################

# Set the timezone for the scheduler forcely (optional)
# If it is running on a VM, and
#   "ValueError: Timezone offset does not match system offset"
#   was raised during scheduling.
# Please uncomment the following line and set a timezone for the scheduler.
# Otherwise it will detect the timezone from the system automatically.

TIMEZONE = "Asia/Shanghai"
